import { createSlice } from "@reduxjs/toolkit";

const countSlice = createSlice({
    name: 'counter',
    initialState: {
        count: 0
    },
    reducers: {
        increment(prev, { payload }) {
            prev.count += payload
        },
        decrement(prev, { payload }) {
            prev.count -= payload
        },
        ifOddIncrement(prev, { payload }) {
            if (prev.count % 2 !== 0) {
                prev.count += payload
            }
        },
        waitIncrement(prev, { payload }) {
            prev.count += payload
        }
    }
})

export default countSlice.reducer;

export const { increment, decrement, ifOddIncrement, waitIncrement } = countSlice.actions